package a_exception.f_constom;
/*
    模拟注册过程
 */
public class UserDemoTest {
    //模拟数据库中存储的账号
    static String[] users = {"marry","tom","lucy","jack","rose"};

    //检查账号是否正确的方法
    public static boolean checkUserName(String userName) throws UserNameAndPasswordException{
        for (String user : users) {
            if (user.equals(userName)){
                //如果相同则表示用户已存在
                throw new UserNameAndPasswordException
                        (userName + "已经被注册了!!");
            }
        }
        return true;
    }

    public static void main(String[] args) {
        try{
            //调用方法
            boolean b = checkUserName("lucy");
        }catch (UserNameAndPasswordException e){
            //异常处理
            String message = e.getMessage();
            System.out.println(message);
        }


    }
}
